package com.cq.hd.member.controller;

import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbBusinessSubscribeApi;

import com.cq.hd.member.api.dto.BusinessSubscribeDto;
import com.cq.hd.member.api.dto.BusinessSubscribeUpdateDto;
import com.cq.hd.member.api.vo.BusinessSubscribeVo;
import com.cq.hd.member.service.TbBusinessSubscribeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订阅商家表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@RestController
public class TbBusinessSubscribeController implements TbBusinessSubscribeApi {

    @Autowired
    private TbBusinessSubscribeService businessSubscribeService;

    @ApiOperation(value = "根据用户id获取订阅商家id列表")
    @ApiImplicitParam(name = "userId", value = "实体", paramType = "query", dataType = "Long")
    @Override
    public Result<List<Long>> listByUserId(Long userId) {
        return ResultGenerator.success(businessSubscribeService.listByUserId(userId));
    }

    @ApiOperation(value = "商家订阅和取消订阅")
    @ApiImplicitParam(name = "businessSubscribeUpdateDto", value = "实体", paramType = "body", dataType = "BusinessSubscribeUpdateDto")
    @Override
    public Result<Object> updateState(@RequestBody BusinessSubscribeUpdateDto businessSubscribeUpdateDto) {
        return ResultGenerator.success(businessSubscribeService.updateState(businessSubscribeUpdateDto));
    }

    @ApiOperation(value = "根据用户id获取订阅商家id列表")
    @ApiImplicitParam(name = "businessIds", value = "商家id集合", paramType = "query", dataType = "Long")
    @ApiResponse(response = BusinessSubscribeVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<BusinessSubscribeVo>> listByBusinessIds(@RequestBody List<Long> businessIds) {
        return ResultGenerator.success(businessSubscribeService.listByBusinessIds(businessIds));
    }

    @ApiOperation(value = "根据条件获取订阅商家数据")
    @Override
    public Result<List<BusinessSubscribeVo>> listByDto(BusinessSubscribeDto businessSubscribeDto) {
        return ResultGenerator.success(businessSubscribeService.listByDto(businessSubscribeDto));
    }

    @Override
    public Result<Map<Long, Integer>> getBusinessSubscribeCount(List<Long> businessIds) {
        return ResultGenerator.success(businessSubscribeService.getBusinessSubscribeCount(businessIds));
    }
}
